{extend name='admin@formmain'}

{block name='style'}
<style type="text/css">
    .layui-input-block span{display: none!important;}
  /*  .layui-form{padding:10px;}*/
</style>
{/block}

{block name="content"}
{php}
{//var_dump($data['manager_info']);}
{//var_dump($data['company_user_list']);}
{//var_dump($vo);}
{/php}

<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body">

			<div class="layui-form-item">

            {if $userinfo['db1']['authorize'] == 1 || $userinfo['db1']['roleid'] == 1}
              <label class="layui-form-label label-required">指定公司</label>
            <div class="layui-input-block">
                <!-- <input name="department" value='{$vo.department|default=""}' required placeholder="请输入公司名称" class="layui-input"> -->
                <select   class="layui-select" name="companyid" >
                <option value="">-- 选择公司 --</option>

                    {foreach  $data['companylist'] as $key=>$value}
                         {if($value.id == @$vo.companyid )}
                    
                        <option selected value="{$value.id}">{$value.name}</option>
                        {else}
                        <option value="{$value.id}">{$value.name}</option>
                      
                        {/if}
                    {/foreach}
                </select>
            </div>
            {else}
             <!--  <label class="layui-form-label label-required">公司名称</label> -->
                {if @$vo.id}
            <div class="layui-input-block">
                 <input style="color: rgb(255 255 255 / 0%); display: inline;border:0;background-color:#ffffff" readonly name="companyid" value='{$vo.companyid|default=""}' required placeholder="" class="layui-input">
            </div>
                {else}
            <div class="layui-input-block">
                 <input style="color: rgb(255 255 255 / 0%); display: inline;border:0;background-color:#ffffff" readonly name="companyid" value='{$userinfo["db2"]["companyid"]|default=""}' required class="layui-input">
            </div>
                {/if}
                
            {/if}
        </div>
            <div class="layui-form-item">
		    <label class="layui-form-label label-required">部门名称</label>
		    <div class="layui-input-block">

          {if @$vo.is_security ==1}
                <input readonly name="department" value='{$vo.dept_name|default=""}' required placeholder="请输入部门名称" class="layui-input layui-bg-gray">
		      {else}
               <input name="department" value='{$vo.dept_name|default=""}' required placeholder="请输入部门名称" class="layui-input">
          {/if}
		    </div>
		</div>
            <div class="layui-form-item">
        <label class="layui-form-label label-required">部门位置</label>
        <div class="layui-input-block">

                <input name="address" value='{$vo.address|default=""}' required placeholder="请输入部门位置(例:X栋x楼001室)" class="layui-input">
            
        </div>
    </div>

<!--             <div class="layui-form-item">
            <label class="layui-form-label ">部门经理</label>
            <div class="layui-input-block">

                <input name="department" value='{$vo.name|default=""}' required placeholder="请输入用户姓名" class="layui-input">
                
            </div>
        </div> -->
          {if false}
            <div class="layui-form-item">
            <label class="layui-form-label">部门经理</label>

            <div class="layui-input-block">
                {if (@$data.manager_info)}
                        <input style="position: absolute;z-index:2;width: 80%;" autocomplete="off" name="dept_manager_name" value='{$data.manager_info.name|default="暂无"}'  class="layui-input" id="searchname">
                        <i class="layui-icon" style="font-size: 10px; color: #1E9FFF;">&#xe615;</i>  
                    {else}
                        <input style="position: absolute;z-index:2;width: 80%;" autocomplete="off" name="dept_manager_name" value='{$data.manager_info.name|default=""}'  placeholder="请输入公司员工手机号" class="layui-input" id="searchname">
                         <i class="layui-icon" style="left:90%;top:20%;position: absolute;z-index:2;width: 10%;font-size: 20px; color: #1E9FFF;">&#xe615;</i>  
                {/if}           
                 <select id="searchuserlist"  class="layui-input layui-unselect" name="dept_manager_userid" lay-filter="watch" lay-search>
                     <option value="">-- 请选择员工 --</option>
                    {notempty name='data.company_user_list'}
                    {foreach $data.company_user_list as $key=>$value}

                    {if @$value.name == @$data.manager_info.name}
                        <option selected="selected" value="{$value.id}">{$value.name}-联系:{$value.mobile}</option>
                    {else}
                         <option value="{$value.id}">{$value.name}-联系:{$value.mobile}</option>
                    {/if}   
                    {/foreach}
                    {/notempty}

                </select>

            </div>
            <!-- //二维码 -->

                        <div class="layui-input-block">
                          {if $vo.is_security == 1}
                            <a data-modal='{:url("company/user/add")}?dept_id={$vo.id}&is_m=5'>二维码分享-设置部门经理</a>
                          {else}
                            <a data-modal='{:url("company/user/add")}?dept_id={$vo.id}&is_m=3'>二维码分享-设置部门经理</a> 
                          {/if}
            </div>


        </div>
        {/if}
            <div class="layui-form-item">
        <label class="layui-form-label">上班时间</label>

        <div class="layui-input-block">

                {if @$vo.id}
                     <input  type="text" class="layui-input layui-input-inline"  id="scheduling_first" name="scheduling_first" value="{$vo.start_time|default=''}"  placeholder="{$vo.start_time|default='09:00:00'}">  
                    <label class="layui-form-label" style="width: unset;margin-right: 10px;">至</label>
                    <input type="text" class="layui-input layui-input-inline" id="scheduling_last"  name="scheduling_last" value="{$vo.end_time|default=''}"  placeholder="{$vo.start_time|default='18:00:00'}">  
                {else}
                     <input type="text" class="layui-input layui-input-inline" id="scheduling_first" name="scheduling_first" value="08:00:00"  placeholder="请选择上班时间">  
                  至
                    <input type="text" class="layui-input layui-input-inline" id="scheduling_last" name="scheduling_last" value="18:00:00"  placeholder="请选择下班时间">       
                {/if}

            
        </div>
    </div>


<!-- 设置图片开始 -->
        <div class="layui-form-item">
           <label class="layui-form-label">接待处图片</label>
           <!--  <span class="color-green label-required-prev">部门地点图片</span> -->
              <div class="layui-input-block">
            <table class="layui-table">
                <thead>
                <tr>
                    <!-- <th class="text-center">LOGO</th> -->
                    <th class="text-left">接待处导引图片</th>
                </tr>
                <tr>
                 <!--    <td width="90px" class="text-center"><input name="logo" type="hidden" value="{$vo.logo|default=''}"></td> -->
                    <td width="auto" class="text-left">

                {php}
                {
                  if(@$vo['address_image']){
                    $imagelist = json_decode($vo['address_image']);

                    foreach($imagelist as $key=>$value){
                      echo "<div class='uploadimage uploadimagemtl' data-tips-image='".$value."' style='background-image: url(&quot;'".$value."'&quot;);'><a class='layui-icon margin-right-5'></a><a class='layui-icon margin-right-5'>ဆ</a><a class='layui-icon margin-right-5'></a></div>";
                  }

                }
                 }
                {/php}




                      <input name="dept_logo" type="hidden" value="{$vo.image|default=''}"></td>
                </tr>
                </thead>
            </table>

            <script>$('[name="dept_logo"]').uploadMultipleImage()</script>
             </div>
        </div>



{if false}
<div class="layui-form-item">
    <label class="layui-form-label">部门选项</label>

            <div class="layui-input-block">

                <div class="layui-textarea padding-bottom-10" style="min-height:auto">
  <!--               
                <label class="layui-form-label">部门禁/启用</label>
                      <div class="layui-input-block">
                    {if @$vo.status == 1}
                    <input type="checkbox" checked="checked" name="status" lay-skin="switch">
                    {else}
                    <input type="checkbox" name="status" lay-skin="switch">
                    {/if}
                 
                 </div> -->
              </br>
                <label style="width: unset;" class="layui-form-label">部门是否为门卫(保安)部门</label>
                      <div class="layui-input-block">
                {if @$vo.is_security eq 1}
                <input type="checkbox" checked="checked" name="is_security" lay-skin="switch">
                {else}
                <input type="checkbox" name="is_security" lay-skin="switch">
                {/if}
                 
                 </div>
        </br>
            {if @$vo.id}
                <label style="width: unset;" class="layui-form-label">设置部门人员</label>
                      <div class="layui-input-block">
               
                <button type="button" data-modal="{:url('company/user/index')}?dep_id={$vo.id}" data-title="设置部门人员" class='layui-btn layui-btn-sm  layui-btn-normal'>设置部门人员</button>

               
                 
                 </div>
                  {/if}
            </div>

  </div>

</div>
{/if}
     
    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        {if @$vo.id}
        <button data-confirm="确定要编辑部门吗?" class="layui-btn" type='submit'>保 存</button>
        {else}
        <button data-confirm="确定要添加部门吗?" class="layui-btn" type='submit' onclick="test()">保 存</button>

        {/if}
        <button class="layui-btn layui-btn-danger" type='button' data-close>取消编辑</button>
    </div>

    <script>window.form.render();</script>

</form>
<script type="text/javascript">
 layui.use(['laydate','layer','carousel', 'jquery', 'form'], function () {
      var layer = layui.layer,
              $ = layui.jquery;
            form = layui.form;
      var laydate = layui.laydate;
      var carousel = layui.carousel;  
      //部门的地址图片

      //测试
      // var ss = '["http://pc.zsicp.com/upload/18b1250d83bc9747/22c0ac901d7c83f1.png","http://pc.zsicp.com/upload/2daa6e9abe4f44c2/e9af380be8ee82d0.png"]'
      // console.log(JSON.parse(ss))

      //执行一个laydate实例

      laydate.render({
        elem: '#scheduling_first' //指定元素
        ,type: 'time'
        // ,value: '08:00:00'

        
      });
       laydate.render({
        elem: '#scheduling_last' //指定元素
        ,type: 'time'
        // ,value: '18:00:00'

      });
       //编辑设置初始时间
       
       if("{$vo.id}"){
          laydate.render({
            elem: '#scheduling_first' //指定元素
            ,type: 'time'
            ,value: "{$vo.start_time}"
    
            
          });
           laydate.render({
            elem: '#scheduling_last' //指定元素
            ,type: 'time'
            ,value: "{$vo.end_time}"
    
          });
       }
        /**选择用户后搜索**/
      form.on('select(watch)', function(data){
        //console.log(data)
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{id:data.value},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                var reres = JSON.parse(res)
                //console.log(reres)
                if(reres.data.roleid==2){
                  $('.authorize-changer').css({'display':'block'})
                }else{
                  $('.authorize-changer').css({'display':'none'})
                  $('input[name="ch_role"]').val('off');
                }
                $('#searchname').val(reres.data.name+'-联系：'+reres.data.mobile)
                $("input[name='contact_phone']").val(reres.data.mobile)
                $("input[name='contact_mail']").val(reres.data.email)
                $("input[name='dept_manager_userid']").val(reres.data.id)
              }
          })
        });
        //监听搜索
        $("#searchname").on("input",function(e){
            $("#searchuserlist").next().find("dl").css({ "display": "block" });
            //console.log(e.delegateTarget.value);
            $('#searchuserlist').html('')
            form.render('select')
            if(e.delegateTarget.value==''){return;}
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{phone:e.delegateTarget.value,type:'phone'},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                var reres = JSON.parse(res)
                //console.log(res)
                var option = ''
                for (var i = 0; i < reres.data.length; i++) {
                    option = option+"<option value="+reres.data[i].id+">"+reres.data[i].name+"-联系:"+reres.data[i].mobile+"</option>"
                }
                // console.log(reres)
                $('#searchuserlist').append(option)
                $("#searchuserlist").next().addClass('layui-form-selected')
              }
          })
            form.render('select')
            $("#searchuserlist").next().addClass('layui-form-selected')
        });

    });


        $("#singcms-button-submit").click(function() {
        var data = $("#singcms-form").serializeArray();
        postData = {};
        $(data).each(function(i) {
            postData[this.name]= this.value;
        });
        // postData['create_at']=create_at;
        //console.log(postData);
        
        // 将获取到的数据post给服务器
        url = SCOPE.save_url;
        jump_url = SCOPE.jump_url;
        $.post(url, postData, function(result) {
            if (result.code == 200) {
                //成功
                return dialog.success(result.message, jump_url);
            } else if (result.code == 400) {
                // 失败
                return dialog.error(result.message);
            }
        }, "JSON");
    });
    var SCOPE = {
        'save_url' : "{:url('department/department/index')}",
        'jump_url' : "{:url('department/department/index')}",
    
    };
</script>

{/block}